package net.xdclass.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

public class CartVO {
    private List<CartItemVO> cartItems;
    private Integer totalNum;
    private BigDecimal totalPrice;
    private BigDecimal realPayPrice;

    public List<CartItemVO> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItemVO> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getTotalNum() {
        if (this.cartItems != null) {
            int sum = this.cartItems.stream().mapToInt(t -> t.getBuyNum()).sum();
            return sum;
        }
        return 0;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal reduce = BigDecimal.ZERO;
        if (cartItems != null && cartItems.size() > 0) {
            reduce = cartItems.stream().map(t -> t.getTotalAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
        return reduce;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public BigDecimal getRealPayPrice() {
        BigDecimal reduce = BigDecimal.ZERO;
        if (cartItems != null && cartItems.size() > 0) {
            reduce = cartItems.stream().map(t -> t.getTotalAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
        return reduce;
    }

    public void setRealPayPrice(BigDecimal realPayPrice) {
        this.realPayPrice = realPayPrice;
    }

    @Override
    public String toString() {
        return "CartVO{" +
                "cartItems=" + cartItems +
                ", totalNum=" + totalNum +
                ", totalPrice=" + totalPrice +
                ", realPayPrice=" + realPayPrice +
                '}';
    }
}
